package com.sunducation.wts.lifecycle

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry

//不是继承AppCompatActivity的处理方式
class My2Activity : Activity(), LifecycleOwner {

    private lateinit var mRegistry : LifecycleRegistry
    private lateinit var mObserver : My2ActivityLifeCycleObserver
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my2)
        mObserver = My2ActivityLifeCycleObserver()
        mRegistry = LifecycleRegistry(this)
        mRegistry.addObserver(mObserver)
    }

    override fun getLifecycle(): Lifecycle {
        return mRegistry
    }

    override fun onDestroy() {
        super.onDestroy()
        mRegistry.removeObserver(mObserver)
    }
}
